package com.ys.config;

import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;

import com.ys.util.YamlUtils;

public class MyConfig{

    // 全局属性值
    private static Map<String, String> MAP_ALL = new HashMap<String, String>();
    
    /**
     * 获取当前环境
     */
    public static String getActive() {
        return getConfig("spring.profiles.active");
    }
    
    /**
     * 获取文件存放绝对路径
     */
    public static String getProfile() {
        return getConfig("application.profile");
    }

    /**
     * 获取域名
     */
	public static String getUrlDomain() {
        return getConfig("application.urlDomain");
	}

    /**
     * 获取域名
     */
	public static String getUrlUploadAdmin() {
        return getConfig("application.urlDomain") + "/upload";
	}
	
    /**
     * scm给ERP的appId
     */
    public static String getDasAppKey() {
        return getConfig("api.das.appKey");

    }

    /**
     * scm给ERP的appKey
     */
    public static String getDasAppSecret() {
        return getConfig("api.das.appSecret");
    }

    /**
     * 获取1688 APPKEY
     */
    public static String get1688AppKey(){
        return getConfig("api.ali1688.appKey");
    }

    /**
     * 获取1688 AppSecret
     */
    public static String get1688AppSecret(){
        return getConfig("api.ali1688.appSecret");
    }

    /**
     * 获取amazon的awsAccessKey
     * @return
     */
    public static String getAmazonAwsAccessKey(){
        return getConfig("api.amazon.awsAccessKey");
    }

    /**
     * 获取amazon的awsAccessSecret
     */
    public static String getAmazonAwsAccessSecret(){
        return getConfig("api.amazon.awsAccessSecret");
    }

    /**
     * 获取amazon的roleArn
     */
    public static String getAmazonRoleArn(){
        return getConfig("api.amazon.roleArn");
    }

    /**
     * 获取amazon的roleSessionName
     */
    public static String getAmazonRoleSessionName(){
        return getConfig("api.amazon.roleSessionName");
    }

    /**
     * 获取amazon的lwaClientKey
     */
    public static String getAmazonLwaClientKey(){
        return getConfig("api.amazon.lwaClientKey");
    }

    /**
     * 获取amazon的lwaClientSecret
     */
    public static String getAmazonLwaClientSecret(){
        return getConfig("api.amazon.lwaClientSecret");
    }

    /**
     * 获取amazon的lwaEndpoint
     */
    public static String getAmazonLwaEndpoint(){
        return getConfig("api.amazon.lwaEndpoint");
    }

    /**
     * 获取amazon的appId
     */
    public static String getAmazonAppKey(){
        return getConfig("api.amazon.appKey");
    }

    /**
     * 获取amazon的spApiAuthUrl授权地址
     */
    public static String getAmazonSpApiAuthUrl(){
        return getConfig("api.amazon.spApiAuthUrl");
    }

    /**
     * 获取2.0API地址
     */
    public static String getUrlApi2_0(){
        return getConfig("application.urlApi2_0");
    }

    /**
     * 获取1.5API地址
     */
    public static String getUrlApi1_5(){
        return getConfig("application.urlApi1_5");
    }

    /**
     * 获取文件地址
     */
    public static String getUrlFile(){
        return getConfig("application.urlFile");
    }

    /**
     * 获取备份文件夹地址
     */
    public static String getPathDatabaseBackup(){
        return getConfig("application.pathDatabaseBackup");
    }

    /**
     * 获取配置
     */
    public static String getConfig(String key) {
        String value = MAP_ALL.get(key);
        if (value == null) {
            Map<?, ?> yamlMap = null;
            try {
                yamlMap = YamlUtils.loadYaml("application.yml");
                value = String.valueOf(YamlUtils.getProperty(yamlMap, key));
                MAP_ALL.put(key, value != null ? value : "");
                
                if (value == null || value.equals("null") || value.length() == 0) {
                	String activeProfile = String.valueOf(YamlUtils.getProperty(yamlMap, "spring.profiles.active"));
                	Map<?, ?> yamlMap2 = YamlUtils.loadYaml("application-" + activeProfile + ".yml");
                    value = String.valueOf(YamlUtils.getProperty(yamlMap2, key));
                    MAP_ALL.put(key, value != null ? value : "");
        		}
            } catch (FileNotFoundException e) {
            	e.printStackTrace();
            }
        }
        return value;
    }

    /**
     * 获取钉钉企业id
     */
    public static String getDingCorpid(){
        return getConfig("api.dingding.corpid");
    }

    /**
     * 获取钉钉H5应用id
     */
    public static String getDingAgentid(){
        return getConfig("api.dingding.agentid");
    }

    /**
     * 获取钉钉H5应用key
     */
    public static String getDingAppkey(){
        return getConfig("api.dingding.appkey");
    }

    /**
     * 获取钉钉H5应用secret
     */
    public static String getDingAppsecret(){
        return getConfig("api.dingding.appsecret");
    }

    /**
     * 获取钉钉H5应用默认的机器人唯一标识
     */
    public static String getDingRobotAppKey(){
        return getConfig("api.dingding.robotAppKey");
    }

    /**
     * 获取amazon的client_id
     */
    public static String getAmazonClientId(){
        return getConfig("api.amazon.clientId");
    }

    /**
     * 获取amazon的client_secret
     */
    public static String getAmazonClientSecret(){
        return getConfig("api.amazon.clientSecret");
    }


    /**
     * 获取百度千帆应用appid
     */
    public static String getEknowAiAppId(){
        return getConfig("api.baidu.eknowAiAppId");
    }

    /**
     * 获取百度千帆应用apikey
     */
    public static String getEknowAiApiKey(){
        return getConfig("api.baidu.eknowAiApiKey");
    }

    /**
     * 获取百度千帆应用Secret Key
     */
    public static String getEknowAiSecretKey(){
        return getConfig("api.baidu.eknowAiSecretKey");
    }


    /**
     * 百度Elasticsearch参数 :username
     */
    public static String getBaiduElasticsearchUsername(){
        return getConfig("api.baiduelasticsearch.username");
    }

    /**
     * 百度Elasticsearch参数 :password
     */
    public static String getBaiduElasticsearchPassword(){
        return getConfig("api.baiduelasticsearch.password");
    }

    /**
     * 百度Elasticsearch参数 :hostname
     */
    public static String getBaiduElasticsearchHostname(){
        return getConfig("api.baiduelasticsearch.hostname");
    }

    /**
     * 百度Elasticsearch参数 :port
     */
    public static String getBaiduElasticsearchPort(){
        return getConfig("api.baiduelasticsearch.port");
    }


}
